package com.yunze.system.service.impl.yunze;

import com.yunze.common.mapper.mysql.polling.YzCardPollingErrorMapper;

import com.yunze.common.utils.yunze.ListMapUtils;
import com.yunze.common.utils.yunze.PageUtil;
import com.yunze.common.utils.yunze.VeDate;
import com.yunze.system.service.yunze.IYzCardPollingErrorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service
public class YzCardPollingErrorServiceImpl implements IYzCardPollingErrorService {

    @Resource
    private YzCardPollingErrorMapper yzCardPollingErrorMapper;
 /*   @Resource
    private  TdbCardPollingErrorMapper tdbCardPollingErrorMapper;
*/

    @Override
    public Map<String, Object> listError(Map map) {
        Map<String, Object> omp=new HashMap<String, Object>();
        Integer currenPage=map.get("pageNum")!=null?Integer.parseInt(map.get("pageNum").toString()):0;
        Integer pageSize=map.get("pageSize")!=null?Integer.parseInt(map.get("pageSize").toString()):10;

        if (map.get("isToDay") !=null && map.get("isToDay").toString().equals('1')){
            String stringToday = VeDate.dateToStr( new Date());
            map.put("ToDayKey",stringToday);
        }

//        List<Map<String, Object>> testsel = tdbCardPollingErrorMapper.testsel();

        Integer rowCount = yzCardPollingErrorMapper.selMapCount(map); // mysql
//        Integer rowCount = tdbCardPollingErrorMapper.selMapCount(map);  //TDengine
        rowCount=rowCount!=null?rowCount:0;
        PageUtil pu=new PageUtil(rowCount,currenPage , pageSize);//初始化分页工具类
        //数据打包
        map.put("StarRow", pu.getStarRow());
        map.put("PageSize", pu.getPageSize());
        omp.put("Pu", pu);
        omp.put("Data", yzCardPollingErrorMapper.selMap(map)); //mysql



//        List<Map<String, Object>> maps = new ArrayList<>();
//        List<Map<String, Object>> selMap = tdbCardPollingErrorMapper.selMap(map);
//        for (int i = 0; i < selMap.size(); i++) {
//            maps.add(selMap.get(i));
//        }
//        List<Map<String, Object>> endMap = ListMapUtils.CZCUpdTsToString(maps);
//        omp.put("Data", endMap); //TDengine

        return omp;
    }

    @Override
    public boolean upd(Map map) {
        map.put("ts","2022-12-21 13:57:21.967");
       /* Integer num = tdbCardPollingErrorMapper.SelNumByTs(map);
        Integer upd=0;
        //2022-12-19 14:12:58.54
        if (num !=null && num>0 ){
            try {
                upd = tdbCardPollingErrorMapper.upd(map);
            }catch(Exception e){
                System.out.println(e.getMessage());
            }

        }*/

        return false;
    }

    @Override
    public boolean del(Map map) {
        return yzCardPollingErrorMapper.del(map)>0;
    }

    @Override
    public boolean delArr(Map map) {
        return yzCardPollingErrorMapper.delArr(map)>0;
    }

    @Override
    public boolean updArr(Map map) {

        return yzCardPollingErrorMapper.updArr(map)>0;
    }



}
